package algorithm;

public class leetcode_0376 {
    public int wiggleMaxLength(int[] nums) {
        int len=nums.length;
        if(len<2) return len;
        if(len==2&&nums[0]==nums[1]) return 1;
        else if(len==2) return 2;
        int result=len;
        int index=0;
        for(int i=1;i<len-1;++i){
            if((nums[i]-nums[index])*(nums[i+1]-nums[i])<0){
                index=i;
            }
            else{
                result--;
            }
        }
        if(nums[len-1]==nums[index]) result--;
        return result;
    }
}
